package com.twu.biblioteca;

import java.util.ArrayList;

import static javax.swing.JOptionPane.showMessageDialog;

/**
 * Created with IntelliJ IDEA.
 * User: Deepika
 * Date: 5/31/13
 * Time: 12:29 AM
 * To change this template use File | Settings | File Templates.
 */
class BibliotecaLibrary{

    ArrayList<Book> books = new ArrayList<Book>();
    ArrayList<Movies> moviesList = new ArrayList<Movies>();
    ArrayList<User> usersList = new ArrayList<User>();

    public void initialiseBooks() {
        Book b1 = new Book("Gone with the Wind",0);
        Book b2 = new Book("Sherlock Homes",1);
        books.add(b1);
        books.add(b2);
    }

    public void initialiseUsers() {
        User u1 = new User("Deepika","deepika.kamboj22@gmail.com","9899902762","Deepika");
        User u2 = new User("Kanika","deepika.kamboj22@gmail.com","9899902762","Kanika");
        usersList.add(u1);
        usersList.add(u2);
    }

    public boolean checkUser(String username, String password){

        for(User u: usersList){

            if(username.equals(u.getUsername()) && password.equals(u.getPassword())) {
                return(true);
            }
        }

        return(false);
    }


    public void initialiseMovies() {
        Movies[] M = new Movies[15];

        M[0] = new Movies("Sholay",1990,"Ramesh Sippy","1");
        M[1] = new Movies("Ashiqui 2",2013,"Mohit Suri","N/A");
        M[2] = new Movies("3 Idiots",2009,"Rajkumar Hirani","5");
        M[3] = new Movies("Aurangzeb",2013,"Atul Sabharwal","3");
        M[4] = new Movies("Son of Sardar",2012,"Ashwani Dheer","3");
        M[5] = new Movies("Khiladi 786",2012,"Ashish R Mohan","6");
        M[6] = new Movies("Inkaar",2013,"Sudhir Mishra","4");
        M[7] = new Movies("Barfi",2012,"Anurag Basu","5");
        M[8] = new Movies("Dhobi Ghat",2010,"Kiran Rao","4");
        M[9] = new Movies("Ishaqzaade",2012,"Habib Faisal","N/A");
        M[10] = new Movies("Aatma",2013,"Suparn Verma","7");
        M[11] = new Movies("English Vinglish",2012,"Gauri Shinde","8");
        M[12] = new Movies("Yeh Jawani Hai Deewani",2013,"Ayan Mukerji","N/A");
        M[13] = new Movies("Jannat 2",2013,"Kunal Deshmukh","9");
        M[14] = new Movies("Love Aaj Kal",2009,"Imtiaz Ali","9");



        for(int i=0; i<15; i++){
            moviesList.add(M[i]);
        }

    }


    public boolean reserveBooks(Integer index){

        Book b = books.get(index);
        if(b.checkAvailability() == 0){
            showMessageDialog(null, "Sorry we don't have that book yet.");
            return(false);
        }
        else  {
            showMessageDialog(null, "Thank You! Enjoy the book.");
            b.issueBook();
            return(true);
        }
    }

    BibliotecaLibrary(){
        initialiseBooks();
        initialiseMovies();
        initialiseUsers();
    }

    public ArrayList<Book> getAllBooks() {
        return books;
    }

    public ArrayList<Movies> getAllMovies() {
        return moviesList;
    }

    public ArrayList<User> getAllUsers() {
        return usersList;
    }
}
